package com.zmn.oms.task.listener;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.services.interfaces.serviceitem.OrderServiceItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 描述：订单服务项修改监听
 *
 * @author xiewenbing
 * @since 2022/8/11 16:27
 */

@Slf4j
@Component
@AliyunMQListener(topic = "${spring.mq.topic.oms}")
public class OrderServiceItemListener {

    @Autowired
    private OrderServiceItemService orderServiceItemService;

    /**
     * 工单算账消息监听
     * @param message
     */
    @AliyunMQHandler(tags = OmsMqTagConsts.ORDER_SERVICE_ITEM_DEL_MQ_TAG)
    public void orderServiceItemDelete(String message){
        log.info("#MQ#OrderServiceItemDelete# {}", message);

        if (StringUtil.isBlank(message)) {
            return;
        }

        Long proExtId = Long.parseLong(message);
        if (NumberUtil.isNullOrZero(proExtId)) {
            return;
        }

        try {
            orderServiceItemService.deleteByProExtId(proExtId);
        } catch (Exception e) {
            log.error("#MQ#OrderServiceItemDelete occur exception {},{}", e,e.getMessage());
        }
    }
}
